//
//  HouseTypeInfoMessageViewModel.m
//  YiJuZhangShou2.0
//
//  Created by URANUS on 16/4/8.
//  Copyright © 2016年 Mr.X. All rights reserved.
//

#import "HouseTypeInfoMessageViewModel.h"
#import "HouseTypeInfoViewController.h"
#import "HouseTypeInfoMessageModel.h"

@implementation HouseTypeInfoMessageViewModel

#pragma mark - Delegate NetworkingBaseManagerAPISuccessCallbackDelegate
- (void)manager:(NetworkingBaseManager *)manager callAPIDidSuccessWithParams:(NSDictionary *)responseParams{
    DDLogInfo(@"查看户型详情网络返回数据：%@",[responseParams description]);
    NSArray *dataArray = [responseParams objectForKey:@"data"];
    
    NSMutableArray *models = [HouseTypeInfoMessageModel mj_objectArrayWithKeyValuesArray:dataArray];
    
    for (HouseTypeInfoMessageModel *model in models) {
        model.advertisementImageAddress = model.layoutPicture[0];
    }
    
    HouseTypeInfoViewController *houseTypeInfoViewController = self.viewObject;
    houseTypeInfoViewController.models = models;
}

#pragma mark - Public
- (void)loadRequest{
    self.manager = [NetworkingManagerFactory generateNormalManager];
    RequestGenerator *requestGenerator = [RequestGenerator sharedInstance];
    self.manager.apiName = [requestGenerator generateCommonApiWithName:[NSString stringWithFormat:@"projects/%ld/layouts/%ld",[AppContext sharedInstance].projectId,(long)self.layoutId]];
    self.manager.requestType = HTTP_GET;
    self.manager.successDelegate = self;
    self.manager.validator = self;
    [self.manager loadRequest];
}

- (void)setUpMJModel{
   [HouseTypeInfoMessageModel mj_setupReplacedKeyFromPropertyName:^NSDictionary *{
       return @{
                @"houseArea" : @"layoutArea",
                @"houseTypeLocation" : @"layoutLocation",
                @"houseTags" : @"layoutTag",
                @"houseIntroduction" : @"layoutIntroduction",
                };
   }];
}

@end
